package com.example.service.impl;

import com.example.annotations.UserAble;
import com.example.aspect.UserAbleParser;
import com.example.aspect.eldemo.DistributeExceptionHandler;
import com.example.entity.User;
import com.example.service.UserService;
import com.example.vo.UserVO;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {


    @Override
    @UserAble(value = "#user.getName()",
            key = "'==='+#user.getId()+'_'+#user.getAge()",
            proceed = "#"+ UserAbleParser.RETURN_PARAM +".getIsSuccess()")
//    @CachePut(cacheNames="test",key = "#user.getId()+'_'+#user.getName()")
    @DistributeExceptionHandler(attachmentId = "'==='+#user.getId()+'_'+#user.getAge()")
    public UserVO doSomething(User user) {
        System.out.println("user = " + user);
        UserVO vo=new UserVO();
        vo.setUserId(user.getId()+"vo");
        vo.setUserName(user.getName()+"vo");
        vo.setUserAge(user.getAge()+"vo");
        vo.setIsSuccess(false);
        return vo;
    }
//,key = "#user.getId()+'_'+#user.getName()"
    @Override
    @Cacheable(cacheNames="test",key = "#user.getId()+'_'+#user.getName()")
    public UserVO doSomething2(User user) {
        UserVO vo=new UserVO();
        vo.setUserId(user.getId()+"vo");
        vo.setUserName(user.getName()+"vo");
        vo.setUserAge(user.getAge()+"vo");
        vo.setIsSuccess(false);
        return vo;
    }
}
